Questions
8 of 25
1How do you implement a local (username/password) Passport strategy in NestJS?
2How do you register a global JWT guard so all routes are protected by default in NestJS?
3What is RBAC and how do you implement a basic roles guard in NestJS?
4What is the difference between RBAC and ABAC and when would you use each in NestJS?
5How does the OAuth2 authorization code flow work and how do you implement it with Passport in NestJS?
6How do you implement API key authentication as an alternative to JWT in NestJS?
7How do you implement multi-tenant authentication where each tenant has its own JWT secret in NestJS?
8How do you implement JWT refresh token rotation with secure storage in NestJS?
9How do you implement ABAC with CASL in a NestJS application?
10What is the difference between JWT and session-based authentication and when do you choose each in NestJS?
11How do you implement two-factor authentication (2FA) with TOTP in NestJS?
12How do you implement permission-based authorization at the field level in a GraphQL resolver in NestJS?
13How do you test authentication guards and strategies in NestJS?
14What is Passport.js and how does it integrate with NestJS?
15How do you implement row-level (resource-level) authorization to ensure users can only access their own records in NestJS?
16What is PKCE and when is it required in OAuth2 flows in NestJS?
17How do you implement an OAuth2 Authorization Server in NestJS?
18How do you implement session-based authentication in NestJS?
19How does the validate() method in a Passport strategy relate to the NestJS request lifecycle?
20How do you implement JWT authentication in NestJS with access and refresh tokens?
21What should and should not go inside a JWT payload?
22How do you implement JWT token revocation (blacklisting) without a database lookup on every request in NestJS?
23What is the difference between AuthGuard('jwt') from Passport and writing a custom JwtAuthGuard in NestJS?
24How do you secure session cookies against common attacks (CSRF, XSS, session fixation) in NestJS?
25How do you implement brute force protection on the login endpoint in NestJS?
08 / 25

How do you implement JWT refresh token rotation with secure storage in NestJS?

Hash the refresh token with bcrypt before storing in the database. On each refresh, verify the incoming token against the hash, issue a new token pair, invalidate the old refresh token, and store the new hash. Reuse of a rotated token should trigger a full logout of all sessions as a theft signal.

Refresh token rotation with hashed storage
Refresh token rotation security rules:
  1. 1

    Rotation invalidates the old refresh token on every use — only the latest token is valid.

  2. 2

    Detected reuse of a rotated token is a signal of theft — revoke all sessions for that user immediately.

  3. 3

    Never store refresh tokens in plain text — always hash with bcrypt before persisting.

  4. 4

    Set hashedRefreshToken to null on logout so the token cannot be used after the user signs out.

  5. 5

    passReqToCallback: true allows the strategy's validate() to access the raw refresh token from the request body.